// pages/memberCard/index.js
let App=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navIndex: 0,
    saleCardList:[],
    myCardList:[],
    cardData: {
      photo: "../../images/banner.png",
      nickName: "一个柠檬",
      number: "YH123456"
    },
  },
  onLoad(options){
    this.setData({
      navIndex:options.navIndex
    })
    this.getSaleCardList()
    this.getAd()
  },
  onShow(){
    this.getMyCardList()
  },
  //获取在售会员卡
  getSaleCardList(){
    return new Promise((resolve,reject)=>{
      let PageIndex = this.data.integralPage
      let PageSize = this.data.integralSize
      App._get('Card/Api001', {PageIndex, PageSize}, (res) => {
        let saleCardList=res.data.map(item=>{
          item.bgUrl=item.cardLogo
          return item
        })
        this.setData({saleCardList})
        resolve()
      });
    })
  },
  //获取我的会员卡
  getMyCardList(){
    return new Promise((resolve,reject)=>{
      let PageIndex = this.data.integralPage
      let PageSize = this.data.integralSize
      App._get('Card/Api003', {PageIndex, PageSize}, (res) => {
        let myCardList=res.data.map(item=>{
          item.bgUrl=item.cardLogo
          return item
        })
        this.setData({myCardList})
        resolve()
      });
    })
  },
  //获取广告图
  getAd(){
    App._get('Site/Api007', {}, (res) => {
      this.setData({advInfo:res.data})
    });
  },
  handleNav(e) {
    this.setData({
      navIndex: e.currentTarget.dataset.index
    })
  }
})